<?php
/**
 * Created by PhpStorm.
 * User: mengfeng
 * Date: 2017/9/10
 * Time: 22:15
 */
namespace app\admin\logic;

use tool\Common;
use think\Db;

class Cat extends Base
{
    //谦程网络添加二级分类
    public function addType()
    {
        $roleID = $this->getRoleID();
        if ($roleID != 3) {
            return Common::rm(-2,'您没有权限操作');
        }
        $check = $this->check(__FUNCTION__);
        if ($check['code'] != 1) {
            return $check;
        }
        if (!$this->data['parentID']) {
            return Common::rm(-2,'请选择一级分类');
        }
        $dbTypeName = Db::name('cat')->where('name',$this->data['name'])->select();
        if ($dbTypeName) {
            return Common::rm(-2,'二级分类名称已存在');
        }
        $ar = [
            'parentID' => $this->data['parentID'],
            'name' => $this->data['name'],
            'addtime' => THINK_START_TIME
        ];
        $res = Db::name('cat')->insert($ar);
        if ($res) {
            return Common::rm(1, '分类添加成功');
        } else {
            return Common::rm(-2, '分类添加失败');
        }
    }
}